﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class admin_user_UpdateUser : System.Web.UI.Page
{
    static User user;

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            // hide info panel by default
            ltrInfo.Text = "hide";
        }
        else
        {
            // reset result message
            ltrResultMessage.Text = "";
        }
    }

    protected void btnSearch_Click(object sender, EventArgs e)
    {
        user = UserManagement.GetUser(txtUserName.Text.Trim());
        if (user != null)
        {
            txtFullName.Text = user.Fullname;
            txtEmail.Text = user.Email;
            txtCustomeInfo.Text = user.CustomInfo;
            txtOrganization.Text = user.Organization;
            chbReciveEmail.Checked = user.EnableEmailNotification;

            // show info panel
            ltrInfo.Text = "";
        }
        else
        {
            ltrResultMessage.Text = "Cannot find user with username \"" + txtUserName.Text + "\". Please try again!";
            // hide info panel
            ltrInfo.Text = "hide";
        }
    }

    protected void btnUpdate_Click(object sender, EventArgs e)
    {
        if (Master.Master.CurrentUserManagement.UpdateUser(user.Username, txtPassWord.Text, txtFullName.Text, txtEmail.Text, chbReciveEmail.Checked, txtOrganization.Text, txtCustomeInfo.Text, int.Parse(txtBugPerPage.Text)))
        {
            // hide detailed info
            ltrInfo.Text = "hide";

            // show success message
            ltrResultMessage.Text = "New User Information Updated Successfully!";
        }
        else
            ltrResultMessage.Text = "Fail to update new information. Possibly due to Database Error!";
    }
}